﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_QPGJGControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (Page.Request["id"] != null)
            {
                string sql = "update zs_project set 部门申请状态 =1 where id ='" + Page.Request["Id"] + "'";
                _EluZSDataProvider.RunSqlNon(sql);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "ok", "<script>alert('申请成功！')</script>");
            }
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            Bind();
            CustomGridView GridList = (CustomGridView)FindControl("CustomGridList1");
            if (_EluZSDataProvider.IsNetZSAdmin(userid) || _EluZSDataProvider.IsZSAdmin(userid) || _EluZSDataProvider.IsQZSBM(userid))
            {
                
               GridList.Columns[9].Visible = true;
            }

            
            
        }
        protected void Go_Search(object sender, EventArgs e)
        {
            Bind();
        }
        protected void Bind()
        {
            CustomGridView CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            CustomGridList1.RowCreated += new GridViewRowEventHandler(CustomGridList1_RowCreated);
            Button btnsearch = (Button)FindControl("btnSeach");
            btnsearch.Click += new EventHandler(Go_Search);
            DataTable dt = _EluZSDataProvider.GetProList("",GetSqlWhere());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataKeyNames = new string[] { "ID", "部门申请状态" };
            CustomGridList1.DataBind();
           
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
           
        }

        protected void CustomGridList1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            CustomGridView GridList = (CustomGridView)FindControl("CustomGridList1");
            foreach (GridViewRow gvr in GridList.Rows)
            {
                if (GridList.DataKeys[gvr.RowIndex].Values["部门申请状态"].ToString() == "1")
                {
                    Label lbl_sq = (Label)gvr.FindControl("lbl_sq");
                    lbl_sq.Visible = false;
                }
            }
        }

       



        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
          
            Bind();
        }
        protected string GetSqlWhere() {
            string sqlWhere = string.Empty;
            TextBox txtProName = (TextBox)FindControl("txtProName");
            TextBox txtProNo = (TextBox)FindControl("txtProNo");
            TextBox txtComm = (TextBox)FindControl("txtComm");
            string proName = txtProName.Text;
            string proNo = txtProNo.Text;
            string jsComm = txtComm.Text;

            if (!string.IsNullOrEmpty(proName))
            {
                sqlWhere += " and t.项目名称 like '%" + proName + "%'";
            }
            if (!string.IsNullOrEmpty(proNo))
            {
                sqlWhere += " and t.立项号 like '%" + proNo + "%'";
            }
            if (!string.IsNullOrEmpty(jsComm))
            {
                sqlWhere += " and t.建设单位 like '%" + jsComm + "%'";
            }
            if (_EluZSDataProvider.CkComType(userid) == "评估机构")
            { }
            else
            {
                if (_EluZSDataProvider.IsQZSBM(userid) && !_EluZSDataProvider.IsNetZSAdmin(userid) && !_EluZSDataProvider.IsZSAdmin(userid) && !_EluZSDataProvider.IsSZSB(userid))
                {
                    sqlWhere += @" and (Select tt.ROLENAME  From zs_USER_IN_ROLE t Join  zs_Role tt  On  t.roleid=tt.id
Where  t.userid Like '%" + userid + "%') Like '%'||t.区属||'%' ";
                }
            }
            return sqlWhere;
        }
    }
}


